package cn.stylefeng.guns.modular.goods.service.impl;

import cn.stylefeng.guns.base.pojo.node.TreeviewNode;
import cn.stylefeng.guns.base.pojo.node.ZTreeNode;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goods.entity.LiuGoods;
import cn.stylefeng.guns.modular.goods.mapper.LiuGoodsMapper;
import cn.stylefeng.guns.modular.goods.model.params.LiuGoodsParam;
import cn.stylefeng.guns.modular.goods.model.result.LiuGoodsResult;
import cn.stylefeng.guns.modular.goods.service.LiuGoodsService;
import cn.stylefeng.guns.modular.order.model.params.TbOrderParam;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcl
 * @since 2019-07-09
 */
@Service
public class LiuGoodsServiceImpl extends ServiceImpl<LiuGoodsMapper, LiuGoods> implements LiuGoodsService {
    @Resource
    private LiuGoodsMapper liuGoodsMapper;

    @Override
    public void add(LiuGoodsParam param){
        LiuGoods entity = getEntity(param);
        this.save(entity);
    }

//    @Override
//    public void delete(LiuGoodsParam param){
//        this.removeById(getKey(param));
//    }

    @Override
    public void update(LiuGoodsParam param){
        LiuGoods oldEntity = getOldEntity(param);
        LiuGoods newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LiuGoodsResult findBySpec(LiuGoodsParam param){
        return null;
    }

    @Override
    public List<LiuGoodsResult> findListBySpec(LiuGoodsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LiuGoodsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<ZTreeNode> tree() {
        return this.baseMapper.tree();
    }

    @Override
    public List<TreeviewNode> treeviewNodes() {
        return this.baseMapper.treeviewNodes();
    }

    @Override
    public Page<Map<String, Object>> list(String condition, Long brandId) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.list(page, condition, brandId);
    }

    @Override
    public  List<HashMap<String,String>> selectGossId(TbOrderParam tbOrderParam) {

        String a="1,2,3,4";
        String[] result1 = a.split(",");
       List<String> list=new ArrayList<>();
        LiuGoodsParam l=new LiuGoodsParam();
        for (String b:result1) {
            list.add(b);
        }
        return liuGoodsMapper.selectId(list);
    }

    @Override
    public void updateInventoryQuantity(HashMap<String, String> map) {
        liuGoodsMapper.updateInventoryQuantity(map);
    }

    private Serializable getKey(LiuGoodsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LiuGoods getOldEntity(LiuGoodsParam param) {
        return this.getById(getKey(param));
    }

    private LiuGoods getEntity(LiuGoodsParam param) {
        LiuGoods entity = new LiuGoods();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    public void getByEmId(long id){
        this.liuGoodsMapper.getByEmId(id);
    }



}
